﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using BussinessObject;
using Class_Entity;
using DataAccess;

public partial class Category_Managerment : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            BlindProductToGridview();

        }
 
    }

    protected void BlindProductToGridview()
    {
        BO_Category boca1 = new BO_Category();
        CE_Category ceca1 = new CE_Category();

        GridView1.DataSource = boca1.Load_Category(ceca1);
        GridView1.DataBind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        BO_Category boca = new BO_Category();
        CE_Category ceca = new CE_Category();

        int id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[0].Text);
        ceca._CategoryID = id;
        boca.Delete_Category(ceca);
        BlindProductToGridview();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BlindProductToGridview();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        BO_Category boca = new BO_Category();
        CE_Category ceca = new CE_Category();

        string idtxt = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text;
        int id = Convert.ToInt32(idtxt);
        ceca._CategoryID = Convert.ToInt32(idtxt);
        ceca._CategoryName = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
        boca.Update_Category(ceca);
        GridView1.EditIndex = -1;
        BlindProductToGridview();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BlindProductToGridview();
    }
}
